package com.zeratul.common.i18n.web.mvc;

import com.zeratul.common.core.utils.I18nUtils;
import com.zeratul.common.i18n.config.prop.I18nProperties;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.LocaleResolver;

import java.util.Locale;

@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public class WebMvcLocaleResolver implements LocaleResolver {


    @Autowired
    private I18nProperties i18NProperties;

    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        String language = httpServletRequest.getHeader(i18NProperties.getHeaderName());
        return I18nUtils.getLocale(language, i18NProperties.getDefaultLanguage());
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}
